struct ko;

/* portal调用前的上下文,portal根据ra决定返回位置 */
struct proctx {
    void* ra;
    void* sp;
    int s0;
    int s1;
    int s2;
    int s3;
    int s4;
    int s5;
    int s6;
    int s7;
    int s8;
    int s9;
    int s10;
    int s11;
};

struct trapframe {
    void * ra;
    void * sp;
    int gp;
    int tp;
    int t0;
    int t1;
    int t2;
    int s0;
    int s1;
    int a0;
    int a1;
    int a2;
    int a3;
    int a4;
    int a5;
    int a6;
    int a7;
    int s2;
    int s3;
    int s4;
    int s5;
    int s6;
    int s7;
    int s8;
    int s9;
    int s10;
    int s11;
    int t3;
    int t4;
    int t5;
    int t6;
    void * ksp;
    void * utraphdlr;
    void * kpgtb;
    void * arg;
};

enum proc_stat {
    PROC_UNUSED = 0x0,
    PROC_PROCESSING = 0x1,
    PROC_RUNNABLE = 0x2,
    PROC_RUNNING = 0x3,
    PROC_SLEEP = 0x4,
    PROC_WAITING = 0x5,
    PROC_DEAD = 0x6,
    PROC_ZOMBIE = 0x7
};


struct proc {
    struct proctx ctx; //内核上下文
    int pid;
    enum proc_stat stat;
    struct proc * parent;
    struct proc * childs[NR_PROC]; // 以pid标识
    struct ko * fdtab [NR_MAXOPEN];
    void * scratch;
    void * sleepon;
    struct linkpgs allocpgs; // 分配的页面
    void* mepc;
    void * pgtb;
    struct trapframe * tf; // 用户层程序上下文,trapframe
    struct sleeplk lk;
    struct sleeplk waitlk;
};

